import {action, makeAutoObservable} from "mobx";
import {getUploadToken} from "../apis/UploadApi";

export class QiniuUploadStore {

  token: string|null = null

  timer: NodeJS.Timeout | null = null


  constructor() {
    makeAutoObservable(this)
  }
  
  @action
  async getToken(){
    if (!!this.token) return this.token
    this.token = (await getUploadToken()).data
    if (!this.timer){
      const that = this
      this.timer = setTimeout(()=>{
        that.getToken()
      },15*60*1000)
    }
  }


}

export default new QiniuUploadStore()
